<form class="layui-form" lay-filter="admin_add" id="admin_add">
  <div class="tplay-body">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md6">
          <div class="layui-card-header">账户信息</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input type="text" required name="username" placeholder="用户名" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-col-md6">
              <input type="password" required name="password" placeholder="密码" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-col-md6">
              <input type="password" required name="password_confirm" placeholder="确认密码" autocomplete="off" class="layui-input">
            </div>
          </div>
        <div class="layui-form">
          <div class="layui-card-header">基本资料</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md6">
              <input type="text" required name="nickname" placeholder="昵称" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-col-md6">
              <input type="text" name="phone" required placeholder="手机号" autocomplete="off" class="layui-input">
            </div>
          </div>
        </div>
        <div class="layui-form">
          <div class="layui-card-header">性别</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input type="radio" name="sex" value="1" title="男">
              <input type="radio" name="sex" value="0" title="女" checked>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-col-md6">
          <div class="layui-card-header">备注</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <textarea name="desc" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
          </div>
          <div class="layui-card-header">权限管理</div>
          <div class="layui-card-body">
            <div class="layui-form">
              <div class="layui-form-item">
                <label class="layui-form-label">权限分组：</label>
                <script id="groupList" type="text/html">
                    <div class="layui-form layui-input-block">
                      {{# for(var i = 0;i< d.data.length;i++){ }}
                          <input type="checkbox" name="group_id[]" title="{{ d.data[i].title }}" value="{{ d.data[i].id }}">
                      {{# } }}
                    </div>
                </script>
                <div id="add_view"></div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit="" lay-filter="admin_add_bth">立即提交</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
              </div>
            </div>
          </div>
      </div>
    </div>
  </div>
</form>

<script>
layui.use(['form','laytpl','tplay','layer','apiconfig'], function(){
  var $ = layui.$
  ,laytpl = layui.laytpl
  ,form = layui.form
  ,tplay = layui.tplay
  ,layer = layui.layer
  ,config = layui.apiconfig;
  
  var groups;
  tplay.ajax({url:config.domain+"/admin/index/groups",async:false,success:function(res){groups = res;}});
  var getTpl = $('#groupList').html()
  ,view = document.getElementById('add_view');
  laytpl(getTpl).render(groups, function(html){
    view.innerHTML = html;
  });

  form.render(null, 'admin_add');
  
  form.on('submit(admin_add_bth)', function(data){
    tplay.ajax({
      url:config.domain+"/admin/admin/add",
      data:$('#admin_add').serialize(),
      success:function(res){
        layer.msg(res.msg);
        if(res.code == 1){
          tplay.goBack(1000);
        }
      }
    })
    return false;
  });
});
</script>